package com.gitee.chili.leisure.util;

import lombok.Data;
import org.springframework.lang.NonNull;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;


@Data
public class SimpleThreadFactory implements ThreadFactory {

    public static final String LINUX_BOSS = "linux-boss-";

    public static final String LINUX_WORK = "linux-work-";

    public static final String BOSS = "other-boss-";

    public static final String WORK = "other-work-";

    private String name;

    private final AtomicInteger index = new AtomicInteger(0);

    @Override
    public Thread newThread(@NonNull Runnable r) {
        return new Thread(r, name);
    }

    public SimpleThreadFactory(String name) {
        this.name = Utils.connect(name, String.valueOf(index.incrementAndGet()));
    }

}